package bingo.codeweaver.core.template;

import java.io.File;
import java.io.FileNotFoundException;

import bingo.codeweaver.core.utils.FileHelper;


/**
 * Mar 9, 2009 3:35:09 AM Template.java
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:模板描述元数据
 * ChangeLog:
 */
public class TemplateMetadata {
	/**
	 * 模板名称
	 */
	private String name;
	/**
	 * 模板的类型
	 */
	private String type = "velocity";
	/**
	 * 模板的存放路径
	 */
	private String path;
	/**
	 * 模板文件使用的编码
	 */
	private String encoding = "UTF-8";
	
	public TemplateMetadata() {}
	
	
	
	public TemplateMetadata(String name, String type, String path) {
		this.name = name;
		this.type = type;
		this.path = path;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public String getEncoding() {
		return encoding;
	}
	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}
	public String getTemplateContent() throws FileNotFoundException {
		if(new File(path).exists()){
			return FileHelper.readFileContent(path);
		}else{
			File file = new File(System.getProperty("user.dir", "."),path);
			if(file.exists()){
				return FileHelper.readFileContent(file.getAbsolutePath());
			}
		}
		throw new FileNotFoundException(path);
	}
}
